Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. 'use client';
  2. import { useState } from 'react';
  3. import type { Chat } from '@/types/chat';
  4. import { useParams } from 'next/navigation'
  5. import { useQuery } from '@tanstack/react-query';
  6. import { getChat } from '@/app/api/user/chatService';
  7. const ChatPage: React.FC = () => {
  8. const params = useParams()
  9. const chatID = Number(params.chatID);
  10. const {data:chat, error, isLoading} = useQuery<Chat | undefined>({
  11. queryKey: ["getChat"],
  12. queryFn: () => getChat(chatID)
  13. })
  14. const [enabled, setEnabled] = useState(false);
  15. if(isLoading){
  16. return <p>Loading...</p>
  17. }
  18. if(error){
  19. return <p>Loading...</p>
  20. }
  21. return (
  22. <div className="flex flex-col bg-gray-100 h-screen">
  23. {/* Header */}
  24. <div className="bg-white shadow p-4 flex flex-row">
  25. <div>
  26. <img
  27. src="/default-avatar.png"
  28. alt="Profile"
  29. className="w-15 h-15 rounded-full object-cover border"
  30. />
  31. </div>
  32. <div className='ps-2'>
  33. <p className="text-xl text-gray-500">{}</p>
  34. <p className="text-md text-gray-500">{chat?.persona?.role}</p>
  35. </div>
  36. <div className='ps-2 flex flex-row gap-2 items-center ms-auto'>
  37. <span>Live</span>
  38. <button
  39. onClick={() => setEnabled(!enabled)}
  40. className={`w-12 h-6 flex items-center rounded-full p-1 transition-colors duration-300 ${enabled ? 'bg-blue-500' : 'bg-gray-300'
  41. }`}
  42. >
  43. <div
  44. className={`bg-white w-4 h-4 rounded-full shadow-md transform transition-transform duration-300 ${enabled ? 'translate-x-6' : 'translate-x-0'
  45. }`}
  46. />
  47. </button>
  48. <span>Offline</span>
  49. </div>
  50. </div>
  51. {/* Chat messages */}
  52. <div className="flex-1 overflow-y-auto px-4 py-6 space-y-4" style={{ maxHeight: "65vh" }}>
  53. {chat?.chatList.map((msg, index) => (
  54. <div key={index}>
  55. <p className={`mb-1 text-gray-500 ${msg.self ? 'text-left' : 'text-right'}`}>
  56. {msg.self ? 'Visitor' : 'Ruccan Chat'}
  57. </p>
  58. <div className={`flex ${msg.self ? 'justify-start' : 'justify-end'}`}>
  59. <div className={`max-w-xs whitespace-pre-wrap px-4 py-2 rounded-lg text-sm ${msg.self ? 'bg-white text-gray-800 shadow' : 'bg-blue-500 text-white'}`}>
  60. {msg.text}
  61. <div className="text-[10px] mt-1 text-right opacity-70">
  62. {msg.time}
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. ))}
  68. </div>
  69. {/* Input area */}
  70. <div className="p-4 pb-0 bg-white border-t">
  71. <input
  72. type="text"
  73. placeholder="Taip mesej..."
  74. className="w-full border rounded-full px-4 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
  75. />
  76. </div>
  77. </div>
  78. );
  79. };
  80. export default ChatPage;